package com.dbuil.bleshoes.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dbuil.bleshoes.Constant;
import com.dbuil.bleshoes.R;
import com.dbuil.bleshoes.adapter.ProductListAdapter;
import com.dbuil.bleshoes.base.BaseActivity;
import com.dbuil.bleshoes.bean.ProductListBean;
import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//商品列表
public class ProductListActivity extends BaseActivity implements OnRefreshLoadMoreListener, OnItemClickListener {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_top_title)
    TextView tvTopTitle;
    @BindView(R.id.tv_top_right)
    TextView tvTopRight;
    @BindView(R.id.img_top_right)
    ImageView imgTopRight;
    @BindView(R.id.recycle_productlist)
    RecyclerView mRecycle;
    @BindView(R.id.refresh_productlist)
    SmartRefreshLayout mRefresh;

    @Override
    public int getLayoutId() {
        return R.layout.activity_product;
    }


    @Override
    public void initView() {
        super.initView();

        mRefresh.setOnRefreshLoadMoreListener(this);
        mRecycle.setLayoutManager(new GridLayoutManager(this, 2));
        mRecycle.addItemDecoration(new GridSpacingItemDecoration(2, SizeUtils.dp2px(11), true));
    }

    private List<ProductListBean> listdata = new ArrayList<>();

    @Override
    public void initData() {
        super.initData();

        String title = getIntent().getStringExtra(Constant.PRODUCTTITLE);
        if (!TextUtils.isEmpty(title)) {
            tvTopTitle.setText(title);
        }


        for (int i = 0; i < 18; i++) {
            listdata.add(new ProductListBean());
        }
        ProductListAdapter mAdapter = new ProductListAdapter(listdata);
        mAdapter.setOnItemClickListener(this);
        mRecycle.setAdapter(mAdapter);

    }

    @OnClick(R.id.img_back)
    public void onViewClicked() {
        this.finish();
    }


    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

    }


    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        ActivityUtils.startActivity(ProductDetailActivity.class);
    }

}


